using System.Reflection;

namespace LogikBug
{
	/// <summary>
	/// 
	/// </summary>
	public static class MemberInfoExtensions
	{
		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TAttribute"></typeparam>
		/// <param name="type"></param>
		/// <returns></returns>
		public static TAttribute GetAttribute<TAttribute>(this MemberInfo type)
		{
			TAttribute[] attributes = type.GetCustomAttributes(typeof(TAttribute), true) as TAttribute[];

			if (attributes.IsNotNull() && attributes.Length != 0)
			{
				return attributes[0];
			}

			return default(TAttribute);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TAttribute"></typeparam>
		/// <param name="type"></param>
		/// <returns></returns>
		public static TAttribute[] GetAttributes<TAttribute>(this MemberInfo type)
		{
			return type.GetCustomAttributes(typeof(TAttribute), false) as TAttribute[];
		}
	}
}